﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Rhino.Mocks;
using Chefbook.DataAccessLayer;
//using Chefbook.DataObjects;

namespace UnitTests.DataObjectsTests
{
    [TestFixture]
    public class IngredientFixture
    {
        private MockRepository mocks = new MockRepository();
        private Recipe recipe;
        private Ingredient testIngredient;
        [SetUp]
        public void Init()
        {
            var category = new Category();
            recipe = new Recipe();
            testIngredient = new Ingredient();
            recipe.AddIngredient(testIngredient);
        }

        [Test]
        public void ConstructorTest()
        {
            Assert.AreEqual("", testIngredient.Name, "Constructor Name test failed");
            Assert.AreEqual("", testIngredient.Units, "Constructor Units test failed");
            Assert.AreEqual(0.0, testIngredient.Amount, "Constructor Amount test failed");
            Assert.AreEqual(recipe, testIngredient.Recipe, "Ingredient's Recipe property didn't point at the containing Recipe");
            Assert.AreEqual(1, recipe.Ingredients.Count((i) => i == testIngredient), "Recipe's ingredients didn't containe exactly one copy of Root");
        }

        [Test]
        public void RenameTest()
        {
            testIngredient.Name = "Ground Beef";
            Assert.AreEqual("Ground Beef", testIngredient.Name, "Rename test failed");
        }

        [Test]
        public void RenameNullTest()
        {
            Assert.Throws<System.Data.ConstraintException>(() => testIngredient.Name = null);
        }

        [Test]
        public void ChangeUnitsTest()
        {
            testIngredient.Units = "Lb";
            Assert.AreEqual("Lb", testIngredient.Units, "Change Units test failed");
        }

        [Test]
        public void ChangeUnitsNullTest()
        {
            Assert.Throws<System.Data.ConstraintException>(() => testIngredient.Units = null);
        }

        [Test]
        public void ChangeAmountTest()
        {
            testIngredient.Amount = 1;
            Assert.AreEqual(1, testIngredient.Amount, "Change Amount test failed");
        }

        [Test]
        public void ChangeAmountNegativeTest()
        {
            Assert.Throws<ArgumentException>(() => testIngredient.Amount = (decimal)-0.1);
        }
    }
}
